home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b14
/
Interface
/
WindowInt.c
< prev
next >
Wrap
Text File
|
1996-04-11
|
11KB
|
538 lines
/*****
*
* WindowInt.c
*
* This is a support file for "Grant's CGI Framework".
* Please see the license agreement that accompanies the distribution package
* for licensing details.
*
* Copyright ©1995,1996 by Grant Neufeld
* grant@acm.com
* http://arpp.carleton.ca/grant/
*
*****/
#include "MyConfiguration.h"
#if kCompileWithForeground
#include "compiler_stuff.h"
#include "globals.h"
#include "AboutBox.h"
#include "DebugUtil.h"
#include "MemoryUtil.h"
#include "MenuFunc.h"
#include "ProcessUtil.h"
#include "WindowInt.h"
/*** LOCAL PROTOTYPES ***/
static Boolean windowValid ( WindowPtr );
static Boolean windowHasScrollbars ( WindowPtr );
static void invalidateScrollbars ( WindowPtr );
/*** FUNCTIONS ***/
/* MENU SELECTION HANDLING */
/* */
void
WindowMenuClose ( short modifiers )
{
WindowClose ( NULL, modifiers, true );
} /* WindowMenuClose */
/* EVENT HANDLING */
/* I think that state should be true if it is activating, false if deactivating.
IM-MTE: 2-53,54 */
void
WindowActivate ( WindowPtr theWindow, Boolean activate, const EventRecord *theEvent )
{
window_type windType;
windType = WindowType ( theWindow );
/* restore or hide/reduce-to-outline window's selections */
switch ( windType )
{
#if kCompileWithApplicationWindows
case Window_Application :
CustomActivateWindow ( theWindow, activate );
break;
#endif
case Window_dlgModal :
case Window_dlgMoveableModal :
case Window_about :
case Window_DA :
case Window_UNKNOWN :
default :
break;
}
if ( activate )
{
/* show scroll bars if necessary */
adjustMenus ();
}
else
{
/* hide scroll bars if necessary */
}
} /* WindowActivate */
/* */
void
WindowUpdate ( WindowPtr theWindow )
{
GrafPtr oldPort;
window_type windowType;
windowType = WindowType ( theWindow );
if ( !(windowType == Window_DA) )
{
GetPort ( &oldPort );
SetPort ( (GrafPtr)theWindow );
BeginUpdate ( theWindow );
switch ( windowType )
{
case Window_about :
AboutBoxUpdate ();
break;
case Window_UNKNOWN :
my_assert ( kForceAssert, "\pWindowUpdate: Unknown window type" );
break;
case Window_dlgModal :
case Window_dlgMoveableModal :
case Window_none :
break;
#if kCompileWithApplicationWindows
case Window_Application :
#endif
default :
/* call custom window update procedure */
#if kCompileWithApplicationWindows
CustomUpdateWindow ( theWindow );
#endif
break;
}
EndUpdate ( theWindow );
SetPort ( oldPort );
}
} /* WindowUpdate */
/* MOUSE CLICK HANDLING */
/* see the control manager chapter in IM-MTE for an example DoContentClick procedure
was doInContent */
void
WindowContentClick ( WindowPtr theWindow, const EventRecord *eventPtr, Boolean *onItem )
{
Point whereClicked;
window_type windowType;
GrafPtr savePort;
whereClicked = eventPtr->where;
GetPort ( &savePort );
SetPort ( (GrafPtr)theWindow );
GlobalToLocal ( &whereClicked );
SetPort ( savePort );
windowType = WindowType ( theWindow );
switch ( windowType )
{
case Window_UNKNOWN :
my_assert ( kForceAssert, "\pWindowClose: unknown window type" );
break;
case Window_about :
case Window_dlgModal :
case Window_dlgMoveableModal :
case Window_DA :
break;
/* NOTE: unrecognized windows will be passed to the application
for clicks. */
#if kCompileWithApplicationWindows
case Window_Application :
#endif
default :
#if kCompileWithApplicationWindows
CustomClickInWindow ( theWindow, whereClicked, onItem );
#endif
break;
}
} /* WindowContentClick */
/* was doZoomBox */
void
WindowZoomBox ( WindowPtr theWindow, short partCode )
{
GrafPtr savePort;
GetPort ( &savePort );
SetPort ( theWindow );
EraseRect ( &theWindow->portRect );
ZoomWindow ( theWindow, partCode, false );
invalidateScrollbars ( theWindow );
/* setup for redraw */
InvalRect ( &theWindow->portRect );
SetPort ( savePort );
} /* WindowZoomBox */
/* was doGrowWindow */
void
WindowGrow ( WindowPtr theWindow, Point thePoint )
{
long newSize;
Rect limitRect;
/* set maximum size of window to entire monitor(s) area */
limitRect = gGrayRgnRect;
/* set minimum size of window */
limitRect.left = kMinWindSize;
limitRect.top = kMinWindSize;
/* track user mouse and grow the window */
newSize = GrowWindow ( theWindow, thePoint, &limitRect );
if ( newSize != nil )
{
/* erase and invalidate scroll bar area */
invalidateScrollbars ( theWindow );
SizeWindow ( theWindow, LoWord(newSize), HiWord(newSize), true );
/* relocate scroll bars, then erase and ivalidate scroll bar area */
invalidateScrollbars ( theWindow );
}
} /* WindowGrow */
/* */
#pragma mark -
/* was doCloseWindow */
Boolean
WindowClose ( WindowPtr theWindow, short modifiers, Boolean userInteract )
{
WindowPtr windowToClose;
Boolean theWindowClosed;
#if kCompileWithApplicationWindows
OSErr theErr;
#endif
/* the window ptr must either be NULL or a valid window */
my_assert ( (theWindow == NULL) || (windowValid(theWindow)),
"\pWindowClose: invalid window" );
/* assume function unsuccessful until a window is acutally closed */
theWindowClosed = false;
if ( modifiers & optionKey )
{
/* if the optionKey is active, try to close all open windows */
theWindowClosed = WindowCloseAll ( userInteract );
}
else
{
if ( theWindow == NULL )
{
windowToClose = FrontWindow ();
}
else
{
windowToClose = theWindow;
}
/* do the appropriate type of close based on the kind of window */
switch ( WindowType( windowToClose ) )
{
case Window_about :
AboutBoxClose ();
theWindowClosed = true;
break;
case Window_UNKNOWN :
my_assert ( kForceAssert, "\pWindowClose: unknown window type" );
break;
case Window_dlgModal :
case Window_dlgMoveableModal :
case Window_DA :
break;
/* NOTE: unrecognized windows will be passed to the application
to close. */
#if kCompileWithApplicationWindows
case Window_Application :
#endif
default :
#if kCompileWithApplicationWindows
theErr = CustomCloseWindow ( windowToClose );
theWindowClosed = (theErr == noErr);
#endif
break;
}
}
return theWindowClosed;
} /* WindowClose */
/* was closeAllWindows */
Boolean
WindowCloseAll ( Boolean userInteract )
{
Boolean theWindowsClosed;
WindowPtr theWindow;
theWindowsClosed = true;
theWindow = FrontWindow ();
if ( theWindow != nil )
{
/* keep closing windows until they are all closed, or the user interrupts
or cancels the closing */
do
{
theWindowsClosed = WindowClose ( theWindow, nil, userInteract );
theWindow = FrontWindow ();
/* give other processes time */
ProcessGiveTime ( nil );
} while ( (theWindow != NULL) && (!userInteract || theWindowsClosed) );
}
return theWindowsClosed;
} /* WindowCloseAll */
/* WINDOW KIND TESTING */
#pragma mark -
/* was kindOfWindow */
window_type
WindowType ( WindowPtr theWindow )
{
int windowKind;
windowInfoHdl windInfo;
/* if the window is a null pointer return negative */
if ( theWindow == NULL )
{
return Window_none;
}
windInfo = (windowInfoHdl) GetWRefCon ( theWindow );
if ( windInfo != NULL )
{
return (*windInfo)->wType;
}
windowKind = ((WindowPeek)theWindow)->windowKind;
if ( windowKind < nil )
{
/* desk accessory */
return Window_DA;
}
else if ( windowKind == dialogKind )
{
return Window_dlgModal;
}
else
{
return Window_UNKNOWN;
}
} /* WindowType */
/* */
Boolean
WindowNewSetInfo (
WindowPtr theWindow,
window_type theType,
Boolean hasScrollbars,
long theData )
{
windowInfoHdl theWindInfo;
theWindInfo = WindowNewInfoHdl ( theType, hasScrollbars, theData );
WindowSetInfoHdl ( theWindow, theWindInfo );
return ( theWindInfo != NULL );
} /* WindowNewSetInfo */
/* */
windowInfoHdl
WindowNewInfoHdl (
window_type theType,
Boolean hasScrollbars,
long theData )
{
windowInfoHdl theWindInfo;
theWindInfo = (windowInfoHdl) MemoryNewHandle ( sizeof(windowInfo), NULL );
if ( theWindInfo != NULL )
{
(*theWindInfo)->wType = theType;
(*theWindInfo)->scrollbars = hasScrollbars;
(*theWindInfo)->data = theData;
}
return theWindInfo;
} /* WindowNewInfoHdl */
/* */
void
WindowSetInfoHdl ( WindowPtr theWindow, windowInfoHdl theWindInfo )
{
SetWRefCon ( theWindow, (long)theWindInfo );
} /* WindowSetInfoHdl */
/* */
windowInfoHdl
WindowGetInfoHdl ( WindowPtr theWindow )
{
windowInfoHdl theWindInfo;
theWindInfo = (windowInfoHdl) GetWRefCon ( theWindow );
return theWindInfo;
} /* WindowGetInfoHdl */
/* Return the user specified data from the windowInfoHdl of the window */
long
WindowGetData ( WindowPtr theWindow )
{
windowInfoHdl theWindInfo;
theWindInfo = (windowInfoHdl) GetWRefCon ( theWindow );
if ( theWindInfo == NULL )
{
return nil;
}
else
{
return (*theWindInfo)->data;
}
} /* WindowGetData */
/* Return the user specified data from the windowInfoHdl of the window, as a handle
For backwards compatibility. Avoid using this function. */
Handle
WindowGetDataHdl ( WindowPtr theWindow )
{
return (Handle) (WindowGetData(theWindow));
} /* WindowGetDataHdl */
/* */
void
WindowDisposeInfoHdl ( WindowPtr theWindow )
{
Handle theWindInfo;
theWindInfo = (Handle) GetWRefCon ( theWindow );
if ( theWindInfo != NULL )
{
DisposeHandle ( theWindInfo );
}
} /* WindowDisposeInfoHdl */
/* MISC UTILITIES */
/* */
static Boolean
windowValid ( WindowPtr theWindow )
{
Boolean isValid;
if ( theWindow == NULL )
{
isValid = false;
}
else
{
/* need more tests here */
isValid = true;
}
return isValid;
} /* windowValid */
/* */
static Boolean
windowHasScrollbars ( WindowPtr theWindow )
{
windowInfoHdl windInfo;
windInfo = (windowInfoHdl) GetWRefCon ( theWindow );
if ( windInfo != NULL )
{
return (*windInfo)->scrollbars;
}
else
{
return false;
}
} /* windowHasScrollbars */
/* Invalidate the graphic region encompasing the scrollbars so that they will be
properly updated. */
static void
invalidateScrollbars ( WindowPtr theWindow )
{
Rect tempRect;
if ( windowHasScrollbars(theWindow) )
{
SetPort ( theWindow );
/* invalidate & erase vertical (right-hand side) scrollbar */
tempRect = theWindow->portRect;
tempRect.left = tempRect.right-15;
InvalRect ( &tempRect );
EraseRect ( &tempRect );
/* invalidate & erase horizontal (bottom) scrollbar */
tempRect = theWindow->portRect;
tempRect.top = tempRect.bottom-15;
InvalRect ( &tempRect );
EraseRect ( &tempRect );
}
} /* invalidateScrollbars */
#endif /* kCompileWithForeground */
/***** EOF *****/